// https://www.lintcode.com/problem/count-1-in-binary/description
// 365. Count 1 in Binary
// Count how many 1 in binary representation of a 32-bit integer.

class Solution {
public:
    /*
     * @param num: An integer
     * @return: An integer
     */
    int countOnes(int num) {
        int cnt = 0;
        while (num)
        {
            num = num & (num - 1);
            cnt++;
        }
        return cnt;
    }
};